package kalambury.db;

import kalambury.KalamburyUtils;

import javax.persistence.*;
import java.util.Collection;

/**
 * Created with IntelliJ IDEA.
 * User: damienix
 * Date: 03.11.12
 * Time: 18:38
 * To change this template use File | Settings | File Templates.
 */
@javax.persistence.Table(name = "user", schema = "", catalog = "kalambury")
@Entity
public class UserEntity {
    private String username;

    @javax.persistence.Column(name = "username")
    @Id
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    private String password;

    @javax.persistence.Column(name = "password")
    @Basic
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        UserEntity that = (UserEntity) o;

        if (password != null ? !password.equals(that.password) : that.password != null) return false;
        if (username != null ? !username.equals(that.username) : that.username != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = username != null ? username.hashCode() : 0;
        result = 31 * result + (password != null ? password.hashCode() : 0);
        return result;
    }

    private Collection<ScoreEntity> scoresByUsername;

    @OneToMany(mappedBy = "userByUser")
    public Collection<ScoreEntity> getScoresByUsername() {
        return scoresByUsername;
    }

    public void setScoresByUsername(Collection<ScoreEntity> scoresByUsername) {
        this.scoresByUsername = scoresByUsername;
    }
}
